<template>
	<div>
		<div class="publicpageview" id="publicpageview">
			<div style="text-align: center;font-weight: bold;margin-top: 20px;">租金调整所汇总表</div>
			<div style="display:flex;margin-top: 10px;flex-flow: row wrap" v-if="topContet">
				<div style="margin-left: 30px;">产别{{topContet.field1}}</div>
				<div style="margin-left: 30px;">管片{{topContet.field2}}</div>
				<div style="margin-left: 30px;">所号{{topContet.field8}}</div>
				<div style="margin-left: 30px;">地址{{topContet.field3}}</div>
				<div style="margin-left: 30px;">建筑形式{{topContet.field7}}</div>
				<div style="margin-left: 30px;">查询日期{{topContet.field4}}</div>
				<div style="margin-left: 30px;">调租日期{{topContet.field5}}</div>
			</div>
			<div style="display: flex;margin-top: 20px;box-sizing: border-box;">
				<div class="list3">所号</div>
				<div class="list4">地址</div>
				<div class="list3">建筑形式</div>
				<div class="list3">面积合计</div>
				<div class="list3">居室面积</div>
				<div class="list3">附属面积</div>
				<div class="list3">附加面积</div>
				<div class="list3">租金合计</div>
				<div class="list3">居室租金</div>
				<div class="list3">附属租金</div>
				<div class="list3">附加租金</div>
			</div>
			<div style="display: flex;box-sizing: border-box;" v-for="(item,index) in list" :key="index">
				<div class="list3">{{item.fieldName1}}</div>
				<div class="list4">{{item.fieldName2}}</div>
				<div class="list3">{{item.fieldName3}}</div>
				<div class="list3">{{item.fieldName4}}</div>
				<div class="list3">{{item.fieldName5}}</div>
				<div class="list3">{{item.fieldName6}}</div>
				<div class="list3">{{item.fieldName7}}</div>
				<div class="list3">{{item.fieldName8}}</div>
				<div class="list3">{{item.fieldName9}}</div>
				<div class="list3">{{item.fieldName10}}</div>
				<div class="list3">{{item.fieldName11}}</div>
			</div>
			<div style="display: flex;box-sizing: border-box;">
				<div class="list3">合计</div>
				<div class="list4"></div>
				<div class="list3"></div>
				<div class="list3">{{hejiObject.fieldName4}}</div>
				<div class="list3">{{hejiObject.fieldName5}}</div>
				<div class="list3">{{hejiObject.fieldName6}}</div>
				<div class="list3">{{hejiObject.fieldName7}}</div>
				<div class="list3">{{hejiObject.fieldName8}}</div>
				<div class="list3">{{hejiObject.fieldName9}}</div>
				<div class="list3">{{hejiObject.fieldName10}}</div>
				<div class="list3">{{hejiObject.fieldName11}}</div>
			</div>
		</div>
		
		<button style="margin: 10px auto 0;display: block;" @click="handleout">打印租金调整所汇总表</button>
	<!-- 	<button style="margin: 10px auto 0;display: block;" v-print="printObj">打印租金调整所汇总表</button>
		<div id="loading" v-show="printLoading"></div> -->
	</div>
</template>

<script>
	import * as XLSX from 'xlsx'
	import dayjs from 'dayjs'
	import {
		houseAdminList,
		addRoom,
		roomDetails,
		updRoom,
		blockList,
		blockDetail
	} from '@/api/industry'
	export default {
		props: {
			blockobj: Object
		},
		name: 'zujintiaozhengmenhui',
		data() {
			return {
				printLoading: true,
				printObj: {
					id: "publicpageview",
					popTitle: '打印预览',
					extraCss: "https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.compat.css",
					beforeOpenCallback(vue) {
						console.log('打开之前')
					},
					openCallback(vue) {
						console.log('执行了打印')
					},
					closeCallback(vue) {
						console.log('关闭了打印工具')
					}
				},
				list:[],
				topContet:{} ,
				hejiObject:{
					fieldName4:0,
					fieldName5:0,
					fieldName6:0,
					fieldName7:0,
					fieldName8:0,
					fieldName9:0,
					fieldName10:0,
					fieldName11:0
				}
			}
		},
		computed: {},
		mounted() { 
			console.log(this.blockobj)
			this.list = this.blockobj.export3List	
			this.topContet = this.blockobj.exportTou
			if(this.list){
				this.list.forEach((item,index)=>{
					this.hejiObject.fieldName4 = Number(this.hejiObject.fieldName4 )+Number(item.fieldName4)
					this.hejiObject.fieldName5 = Number(this.hejiObject.fieldName5 )+Number(item.fieldName5)
					this.hejiObject.fieldName6 = Number(this.hejiObject.fieldName6 )+Number(item.fieldName6)
					this.hejiObject.fieldName7 = Number(this.hejiObject.fieldName7 )+Number(item.fieldName7)
					this.hejiObject.fieldName8 = Number(this.hejiObject.fieldName8 )+Number(item.fieldName8)
					this.hejiObject.fieldName9 = Number(this.hejiObject.fieldName9 )+Number(item.fieldName9)
					this.hejiObject.fieldName10 = Number(this.hejiObject.fieldName10 )+Number(item.fieldName10)
					this.hejiObject.fieldName11 = Number(this.hejiObject.fieldName11 )+Number(item.fieldName11)
				})
			}
		},

		methods: {
			handleout() {
				this.$confirm('此操作将导出该条内容，请确认是否继续操作？', '导出提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					})
					.then(() => {
						let list = this.list
						let outList = []
						this.list.forEach((item, index) => {
							outList.push({
								所号: item.fieldName1,
								地址: item.fieldName2,
								建筑形式: item.fieldName3,
								面积合计: item.fieldName4,
								居室面积: item.fieldName5,
								附属面积: item.fieldName6,
								附加面积: item.fieldName7,
								租金合计: item.fieldName8,
								居室租金: item.fieldName9,
								附属租金: item.fieldName10,
								附加租金: item.fieldName11
							})
						})
						outList.push({
							所号: '合计',
							地址: '',
							建筑形式: '',
							面积合计: this.hejiObject.fieldName4,
							居室面积: this.hejiObject.fieldName5,
							附属面积: this.hejiObject.fieldName6,
							附加面积: this.hejiObject.fieldName7,
							租金合计: this.hejiObject.fieldName8,
							居室租金: this.hejiObject.fieldName9,
							附属租金: this.hejiObject.fieldName10,
							附加租金: this.hejiObject.fieldName11
						})
						// 获取表格数据
						const data = outList
						// 转换数据为工作表
						const worksheet = XLSX.utils.json_to_sheet(data)
						// 创建新的工作簿
						const workbook = XLSX.utils.book_new()
						// 将工作表添加到工作簿
						XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1')
						// 导出Excel文件
						XLSX.writeFile(workbook, '租金调整门汇总表.xlsx')
					})
					.catch(() => {
						this.$message({
							type: 'info',
							message: '已取消导出'
						})
					})
			}
		},
	}
</script>

<style scoped>
	.publicpageview {
		width: 1150px;
		height: auto;
		background-color: #fff;
		margin: 20px auto 0;
		overflow: hidden;
		box-sizing: border-box;
		padding: 20px;
		outline: 1px solid black;
	}

	.list1 {
		width: 100px;
		box-sizing: border-box;
		height: 30px;
		line-height: 30px;
		text-align: center;
		outline: 1px solid black;
	}

	.list2 {
		width: 50px;
		height: 30px;
		line-height: 30px;
		outline: 1px solid black;
		text-align: center;
	}

	.left {
		width: 25px;
		height: 360px;
		outline: 1px solid black;
		line-height: 180px;
		text-align: center;
		box-sizing: border-box;
	}

	.list3 {
		width: 100px;
		height: 20px;
		line-height: 20px;
		outline: 1px solid black;
		text-align: center;
		box-sizing: border-box;
		font-size: 12px
	}

	.list4 {
		width: 150px;
		height: 20px;
		line-height: 20px;
		outline: 1px solid black;
		text-align: center;
		box-sizing: border-box;
		font-size: 12px
	}
</style>